/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
 */

package pl.droidsonroids.gif;

/**
 * 功能描述
 *
 * @author bwx484721
 * @since 2020-07-13
 */
class ConditionVariable {
    private volatile boolean mCondition;

    synchronized void set(boolean state) {
        if (state) {
            open();
        } else {
            close();
        }
    }

    synchronized void open() {
        boolean old = mCondition;
        mCondition = true;
        if (!old) {
            this.notify();
        }
    }

    synchronized void close() {
        mCondition = false;
    }

    synchronized void block() throws InterruptedException {
        while (!mCondition) {
            this.wait();
        }
    }
}